@model PageVM
@{
    var uw = Model.Temp as UserWriting;
    var tt = JArray.Parse(uw.Spare1);
    ViewData["Title"] = uw.UwTitle;

    bool laud = ViewData["uca1"]?.ToString() == "yes";
    bool mark = ViewData["uca2"]?.ToString() == "yes";
}

<link href="/css/home/view.css" rel="stylesheet" asp-append-version="true" />

<div class="container">
    <div class="row">
        <div class="col-md-12">
            <!--标签-->
            <partial name="_PartialViewTag" />
        </div>
    </div>

    <div class="row uwo-box">
        <!--标题-->
        <div class="col-md-12">
            <div class="uwo-title">
                <a href="/home/list/@uw.UwId">@uw.UwTitle</a>
                <input id="hid_wid" type="hidden" value="@uw.UwId" />
            </div>
            <div class="mt-3 text-muted">
                <div class="btn-group float-right btn-min">
                    @if (mark)
                    {
                        <button type="button" class="btn btn-info d-none d-sm-block" id="btnMark" title="取消收藏">
                            <i class="fa fa-cube"></i>
                        </button>
                    }
                    else
                    {
                        <button type="button" class="btn btn-outline-info d-none d-sm-block" id="btnMark" title="收藏">
                            <i class="fa fa-cube"></i>
                        </button>
                    }
                    <button type="button" class="btn btn-outline-info d-none d-sm-block">@uw.UwMark</button>
                </div>

                <div class="btn-group float-right btn-min mr-3">
                    @if (laud)
                    {
                        <button type="button" class="btn btn-success d-none d-sm-block" id="btnLaud" title="取消点赞">
                            <i class="fa fa-thumbs-up"></i>
                        </button>
                    }
                    else
                    {
                        <button type="button" class="btn btn-outline-success d-none d-sm-block" id="btnLaud" title="点赞">
                            <i class="fa fa-thumbs-up"></i>
                        </button>
                    }
                    <button type="button" class="btn btn-outline-success d-none d-sm-block">@uw.UwLaud</button>
                </div>

                <span>
                    <partial name="_PartialMakeTag" model="@uw.Spare1" />
                </span>
                <span class="mx-3">
                    <i class="fa fa-user text-muted"></i>
                    <a href="/user/id/@uw.Uid">@uw.Spare2</a>
                    <input id="hid_uid" type="hidden" value="@uw.Uid" />
                </span>
                <span class="text-nowrap mr-3">
                    <i class="fa fa-clock-o text-muted"></i>
                    发布于：@VisualFormat.Duration(uw.UwCreateTime.Value)
                </span>
                <span class="text-nowrap mr-3">
                    <i class="fa fa-clock-o text-muted"></i>
                    更新于：@VisualFormat.Duration(uw.UwUpdateTime.Value)
                </span>
                <span>
                    <i class="fa fa-eye text-muted"></i> @uw.UwReadNum
                </span>
            </div>
        </div>

        <div class="col-md-12">
            <hr />

            @if (uw.UwStatus != 1)
            {
                <h3 class="bg-danger text-white text-center py-3">受 限 制 的 文 章</h3>
            }
        </div>

        <!--内容-->
        <div class="col-md-12 my-3">
            <div class="uwo-content markdown-body">
                @(new Microsoft.AspNetCore.Html.HtmlContentBuilder().AppendHtml(uw.UwContent))
            </div>
        </div>

        <!--回复列表-->
        <div class="col-md-12">
            <div class="uwo-reply mt-5">
                @if (Model.Pag.Total > 0)
                {
                    var listRp = Model.Rows as List<UserReply>;
                    int lv = (Model.Pag.PageNumber - 1) * Model.Pag.PageSize;

                    <h5><span class="float-right">第 @Model.Pag.PageNumber 页</span>@Model.Pag.Total 个留言</h5>

                    <ul class="list-unstyled">
                        @foreach (var item in listRp)
                        {
                            lv += 1;
                            var gra = "https://www.gravatar.com/avatar/" + Netnr.Core.CalcTo.MD5(item.UrAnonymousMail ?? "") + "?r=pg";

                            <li class="media uwo-reply-item py-3" id="no_@lv">
                                @if (item.Uid == 0)
                                {
                                    <img class="imgup" src="@gra" alt="头像" onerror="this.src = '/favicon.svg'; this.onerror = null;">
                                }
                                else
                                {
                                    var avatarpath = "/favicon.svg";
                                    if (!string.IsNullOrWhiteSpace(item.Spare2))
                                    {
                                        avatarpath = GlobalTo.GetValue("StaticResource:Server") + GlobalTo.GetValue("StaticResource:AvatarPath");
                                        avatarpath += "/" + item.Spare2;
                                    }

                                    <img class="imgup" src="@avatarpath" alt="头像" onerror="this.src = '/favicon.svg'; this.onerror = null;">
                                }

                                <div class="media-body ml-2" id="r_@item.UrId">
                                    @if (item.Uid == 0)
                                    {
                                        <a href="@item.UrAnonymousLink">@item.UrAnonymousName</a>
                                        <span class="badge badge-light" title="匿名用户">Guest</span>
                                    }
                                    else
                                    {
                                        <a href="/user/id/@item.Uid">@item.Spare1</a>
                                    }
                                    <small class="text-muted ml-3">
                                        @VisualFormat.Duration(item.UrCreateTime.Value, 1)
                                    </small>
                                    <a href="#no_@lv" class="float-right badge badge-light">@lv</a>
                                    <div class="mt-2">
                                        @if (item.UrStatus == 1)
                                        {
                                            <div class="markdown-body display-section">@(new Microsoft.AspNetCore.Html.HtmlContentBuilder().AppendHtml(item.UrContent))</div>
                                        }
                                        else
                                        {
                                            <em class="badge badge-secondary" title="该信息已被屏蔽">block</em>
                                        }
                                    </div>
                                </div>
                            </li>
                        }
                    </ul>
                }
            </div>
            <partial name="_PartialPaging4" />
        </div>
    </div>

    <div class="row mt-5">
        <!--回复帖子-->
        <div class="col-md-12">
            <h5>回复</h5>
        </div>
        @if (!ViewContext.HttpContext.User.Identity.IsAuthenticated)
        {
            <div class="col-sm-4 mb-3">
                <div class="input-group">
                    <div class="input-group-prepend">
                        <div class="input-group-text">昵称</div>
                    </div>
                    <input class="form-control" aria-label="昵称" id="WrAnonymousName" placeholder="请输入昵称" maxlength="20">
                </div>
            </div>
            <div class="col-sm-4 mb-3">
                <div class="input-group">
                    <div class="input-group-prepend">
                        <div class="input-group-text">邮箱</div>
                    </div>
                    <input class="form-control" aria-label="邮箱" id="WrAnonymousMail" placeholder="根据邮箱从 Gravatar 获取头像" maxlength="50">
                </div>
            </div>
            <div class="col-sm-4 mb-3">
                <div class="input-group">
                    <div class="input-group-prepend">
                        <div class="input-group-text">链接</div>
                    </div>
                    <input class="form-control" aria-label="链接" id="WrAnonymousLink" placeholder="请输入链接，以 http 开头" maxlength="50">
                </div>
            </div>
        }
        <div class="col-md-12">
            <div>
                <div id="replyeditor"></div>
            </div>
            <button id="btnReply" class="btn btn-warning mt-3">提交</button>
        </div>
    </div>
</div>

<partial name="_PartialQuote" model="@("netnrmd.css,netnrmd.js,monaco-editor")" />

<script src="/js/home/list.js" async defer asp-append-version="true"></script>